function loadXMLDoc() {
        var xmlhttp;
        xmlhttp = new XMLHttpRequest();

        xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            var json = JSON.parse(xmlhttp.responseText);
            console.log(json);
            for(let i = 0; i <json.data.length;i++){
                var li = document.createElement("li");

                var span1 = document.createElement("span");
                var span2 = document.createElement("span");
                var span3 = document.createElement("span");

                span1.innerHTML = json.data[i].studentName;
                span2.innerHTML = json.data[i].sex;
                span3.innerHTML = json.data[i].age;

                li.appendChild(span1);
                li.appendChild(span2);
                li.appendChild(span3);

                document.querySelector(".text").appendChild(li);
            }
        }
    };
    xmlhttp.open("GET","http://localhost/ajaxApi/public/index.php/index/student/student",true);
    xmlhttp.send();
}
loadXMLDoc();

document.querySelector("#btn").addEventListener("click",function(){
    var n = document.querySelector('#n').value;
    var s = document.querySelector('#s').value;
    var a = document.querySelector('#a').value;
if(n != "" && a != ""){
    var v;
    v = new XMLHttpRequest();
    v.onreadystatechange=function() {
        if (v.readyState==4 && v.status==200) {
            document.querySelector(".text").innerHTML = "";
            loadXMLDoc();
        }
    };
    v.open("GET","http://localhost/ajaxApi/public/index.php/index/student/addStudent?studentName="+n+"&sex="+s+"&age="+a,true);
    v.send();
}else{
    alert("请输入姓名和年龄")
}
});